package se.webbzon.boltzmann.editor.factory.propertyframe;

import java.util.Collection;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

import se.webbzon.boltzmann.camera.FixedCamera;
import se.webbzon.boltzmann.editor.component.dependencylist.DependencyComboBox;
import se.webbzon.boltzmann.editor.mvc.EditorModel;
import se.webbzon.boltzmann.editor.propertyframe.WorldObjectPropertyFrame;
import se.webbzon.oschi01.worldobject.WorldObject;
import se.webbzon.oschi01.worldobject.WorldStaticObject;

public class FixedCameraPropertyFrameFactory implements PropertyFrameFactory {
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public String getWorldObjectName() {
		return FixedCamera.worldObjectName;
	}

	@Override public WorldObjectPropertyFrame makePropertyFrame(EditorModel model,
																WorldObject instance) {
		return new PropertyFrameImpl(model,(FixedCamera) instance);
	}
	
	/*============================================================
	Private Classes
	============================================================*/
	
	/** An implementation of a property frame. **/
	private static final class PropertyFrameImpl extends WorldObjectPropertyFrame {
		
		// The combo boxes of this panel
		private final DependencyComboBox<WorldStaticObject> platformInput, targetInput;
	
		/*============================================================
		Constructors
		============================================================*/
	
		public PropertyFrameImpl(EditorModel model, FixedCamera c) {
			super(model,c);
			
			// Create camera panel
			JPanel cameraPanel = new JPanel();
			cameraPanel.setLayout(new BoxLayout(cameraPanel,BoxLayout.Y_AXIS));
			
			platformInput = new DependencyComboBox<WorldStaticObject>(	
											model,WorldStaticObject.class,
											c.getPlatform(),
											"Platform: ");
			platformInput.setBorder(BorderFactory.createTitledBorder(platformInput.getName()));
			
			targetInput = new DependencyComboBox<WorldStaticObject>(	
					model,WorldStaticObject.class,
					c.getTarget(),
					"Target: ");
			targetInput.setBorder(BorderFactory.createTitledBorder(targetInput.getName()));
			
			cameraPanel.add(platformInput);
			cameraPanel.add(targetInput);
			addPanel("Camera",cameraPanel);
			
			initialize();
		}
	
		/*============================================================
		Public Methods
		============================================================*/
	
		public boolean apply(Collection<String> errorMessages) {
			FixedCamera c = (FixedCamera) getInstance();
			c.setPlatform(platformInput.getInstance());
			c.setTarget(targetInput.getInstance());
			return true;
		}
	
	}
	
}



